
clear
set more off
use "$base_out/DWMS_Regresiones.dta", clear


***Elimino secundarias***

drop if secondary==1

***Organizo variable de cambio de directior entre 2015 y 2018***

replace cambio=0 if Cambio_2017==0 & Cambio_2018==0

**************************************************
***Cambio de director como outcome de resultado***
**************************************************

eststo clear
label var PEC_PLUS " "
label var PEC "Grants"
eststo:  reghdfe cambio PEC_PLUS   if treatgroup!="Control" & state!=10, a(estrato)  vce(cluster school_id)
sum cambio if PEC_PLUS==0 & e(sample)==1
estadd scalar ymean2=r(mean)

matrix tempm=e(b)
local tempm=string(tempm[1,1], "%9.2gc")


file open newfile using "$tables/cambio_coef_PEC_PLUS_vs_PEC.tex", write replace
file write newfile "`tempm'"
file close newfile




test PEC_PLUS
if r(p)<0.001 {
	di "peque"
	local tempm ="$<0.001$"
	file open newfile using "$tables/cambio_pvalue_PEC_PLUS_vs_PEC.tex", write replace
	file write newfile "`tempm'"
	file close newfile
}
if r(p)>0.001 {
	di "grande"
	local tempm=string(r(p), "%9.3fc")
	file open newfile using "$tables/cambio_pvalue_PEC_PLUS_vs_PEC.tex", write replace
	file write newfile "`tempm'"
	file close newfile
}
		


esttab using "$tables/Cambio_PEC_PLUSESTRA.tex" ,  fragment se ar2  label b(a2) se(a2) nocon nonumber nomtitles nolines nogaps /// 
	replace collabels(none)  ///
	keep(PEC_PLUS) stats(N ymean2, fmt("%9.2gc" "%9.2gc") labels("No. of obs." "Indirect training mean")) star(* 0.10 ** 0.05 *** 0.01)
	
	
****************************
***Interaccion sobre DWMS***
****************************

***Treatment***

eststo clear

gen covariate=0
gen interplus=0
gen interpec=0


drop covariate interplus interpec

**Creo interacciones**

gen interplus=PEC_PLUS*cambio


gen  covariate=cambio

label var PEC_PLUS " " 
label var PEC " "
label var covariate " "
label var interplus " "

eststo:  reghdfe management_sted3 PEC_PLUS  interplus covariate  if treatgroup!="Control" & state!=10, a(estrato#enumerador)  vce(cluster school_id)
estadd ysumm
sum management_sted3 if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/CambioDWMS_het_1_1.tex" ,  fragment se  label b(a2) se(a2) noobs nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep(PEC_PLUS )  star(* 0.10 ** 0.05 *** 0.01)



***Interaction***

eststo clear

drop covariate interplus

**Creo interacciones**

gen interplus=PEC_PLUS*cambio

gen  covariate=cambio

label var PEC_PLUS " " 
label var PEC " "
label var covariate " "
label var interplus " "

eststo:  reghdfe management_sted3 PEC_PLUS  interplus covariate  if treatgroup!="Control" & state!=10 & secondary!=1, a(estrato#enumerador)  vce(cluster school_id)
estadd ysumm
sum management_sted3 if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/CambioDWMS_het_1_2.tex" ,  fragment se  label b(a2) se(a2) noobs nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep(interplus )  star(* 0.10 ** 0.05 *** 0.01)

***Other variable***
eststo clear



drop covariate interplus 

**Creo interacciones**

gen interplus=PEC_PLUS*cambio

gen  covariate=cambio

label var PEC_PLUS " " 
label var PEC " "
label var covariate " "
label var interplus " "

eststo:  reghdfe management_sted3 PEC_PLUS  interplus covariate  if treatgroup!="Control" & state!=10 & secondary!=1, a(estrato#enumerador)  vce(cluster school_id)
estadd ysumm
sum management_sted3 if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/CambioDWMS_het_1_3.tex" ,  fragment se ar2 label b(a2) se(a2) nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep(covariate ) stats(N ymean2, fmt("%9.2gc" "%9.2fc") labels("No. of obs." "Control mean")) star(* 0.10 ** 0.05 *** 0.01)


******************************
***Interacción sobre PLANEA***
******************************

clear
use "$base_out/alum_pb_2018_modified"

merge m:1 school_id using "$basein/Datos adicionales/Datos_heterogeneos.dta", gen(_het)


merge m:1 school_id using "$base_out/DWMS_Regresiones.dta", gen(_DWMS)

***Elimino secundarias***

drop if secondary==1

***Organizo variable de cambio de directior entre 2015 y 2018***

replace cambio=0 if Cambio_2017==0 & Cambio_2018==0


******************
***KEEP´ONLY PEC VS PEC PLUS******
******************

drop if state==10
drop if treatgroup2=="Control"

***Treatment**

eststo clear

gen covariate=0
gen interplus=0


drop covariate interplus 

**Creo interacciones**

gen interplus=PEC_Plus*cambio
gen interpec=PEC*cambio

gen  covariate=cambio

label var PEC_Plus " " 
label var PEC " "
label var covariate " "
label var interplus " "


eststo: reghdfe prom_pca  PEC_Plus covariate interplus if (treatgroup2!="Control" & state!=10) , cluster(cct_num) a(estrato)
estadd ysumm
sum prom_pca if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/CambioPLANEA_het_1_1.tex" ,  fragment se label b(a2) se(a2) noobs nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep(PEC_Plus)  star(* 0.10 ** 0.05 *** 0.01)



**Interactions**

eststo clear

drop covariate interplus 

**Creo interacciones**

gen interplus=PEC_Plus*cambio

gen  covariate=cambio

label var PEC_Plus " " 
label var PEC " "
label var covariate " "
label var interplus " "


eststo: reghdfe prom_pca  PEC_Plus covariate interplus if (treatgroup2!="Control" & state!=10) , cluster(cct_num) a(estrato)
estadd ysumm
sum prom_pca if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/CambioPLANEA_het_1_2.tex" ,  fragment se  label b(a2) se(a2) noobs nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep( interplus) star(* 0.10 ** 0.05 *** 0.01)



**Other variable**

eststo clear

drop covariate interplus 

**Creo interacciones**

gen interplus=PEC_Plus*cambio

gen  covariate=cambio

label var PEC_Plus " " 
label var PEC " "
label var covariate " "
label var interplus " "


eststo: reghdfe prom_pca  PEC_Plus covariate interplus if (treatgroup2!="Control" & state!=10) , cluster(cct_num) a(estrato)
estadd ysumm
sum prom_pca if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)
esttab using "$tables/CambioPLANEA_het_1_3.tex" ,  fragment se ar2  label b(a2) se(a2) nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep(covariate) stats(N ymean2, fmt("%9.2gc" "%9.2fc") labels("No. of obs." "Control mean")) star(* 0.10 ** 0.05 *** 0.01)





